package net.sf.pulse.android;

import java.util.Set;
import java.util.TreeSet;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;

/**
 * This is the entry point and the main screen of the application.
 * 
 * It contains individual channel panels and the "add channel" button.
 */
public class Monitor extends ListActivity {
	
	public static final int ACTIVITY_ADD_CHANNEL = 0;
	
	public static final int MENU_ID_ADD_CHANNEL = Menu.FIRST;
	public static final int MENU_ID_SELECT_PROFILE = Menu.FIRST + 1;
	
	private final Set<SourceView> sources = new TreeSet<SourceView>();
	
    /**
     * Called when the activity is first created.
     * */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        initSources();
        display();
    }

	private void initSources() {
		// TODO Auto-generated method stub
		
	}

	private void display() {
		// TODO Auto-generated method stub
		
	}
	
	private Set<SourceView> getSources() {
		return sources;
	}
	
	@Override
	public void startActivity(Intent intent) {
		
	}

	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        boolean result = super.onCreateOptionsMenu(menu);
        menu.add(0,MENU_ID_ADD_CHANNEL, 0, R.string.channel_add);
        menu.add(0,MENU_ID_SELECT_PROFILE, 0, R.string.select_profile);
        return result;
    }

	@Override
    public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) {
		case MENU_ID_ADD_CHANNEL:
			addChannel();
			return true;
		}
		return super.onOptionsItemSelected(item);
    }

    @Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
    }
    
	/**
	 * Invoke the activity that either scans the immediate network for existing channels,
	 * or allows to explicitly specify the protocol, host and port of the channel,
	 * or allows to import the meta definition.  
	 */
	private void addChannel() {
		Intent i = new Intent(this, AddChannel.class);
		startActivityForResult(i, ACTIVITY_ADD_CHANNEL);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
	}
}